package com.xiaohai.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohai.common.R;
import com.xiaohai.projo.Log;
import com.xiaohai.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaohai
 * @since 2024-02-24
 */
@RestController
@RequestMapping("/log")
@Slf4j
public class LogController {
    @Autowired
    private LogService logService;

    @GetMapping("/list")
    public R<Page<Log>> list(Integer currentPage, Integer pageSize,String name) {
        log.info("currentPage:{},pageSize:{}", currentPage, pageSize);
        Page<Log> page = new Page<>(currentPage, pageSize);
        LambdaQueryWrapper<Log> logLambdaQueryWrapper = new LambdaQueryWrapper<>();
        logLambdaQueryWrapper.like(name!=null,Log::getDes,name);
        Page<Log> list = logService.page(page,logLambdaQueryWrapper);
        return R.success(list, "获取数据成功");
    }
    @DeleteMapping
    public R<String> delete(Integer id){
        logService.removeById(id);
        return R.success(null,"删除成功");
    }
}
